package com.shyroke.daydayzhuanapi.mapper;

import cn.hutool.core.date.DateUtil;
import com.shyroke.daydayzhuanapi.dto.SpiderProjectDto;
import com.shyroke.daydayzhuanapi.entity.SpiderProjectEntity;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SpiderProjectMapper {
    @Autowired
    private ModelMapper modelMapper;

    public SpiderProjectEntity dtoToEntity(SpiderProjectDto p) {
        return modelMapper.map(p,SpiderProjectEntity.class);
    }

    public SpiderProjectDto entityToDto(SpiderProjectEntity e) {
        SpiderProjectDto dto = modelMapper.map(e, SpiderProjectDto.class);
        dto.setShowDate(DateUtil.format(dto.getDate(),"yyyy-MM-dd"));
        dto.setSource(dto.getSource().substring(0,dto.getSource().indexOf(",")));
        return dto;
    }
}
